package com.bdqn.component;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
public class SpringmvcConfig   extends  WebMvcConfigurerAdapter{

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
			System.out.println("SpringmvcConfig=============================================");
			File f = new File(this.getClass().getResource(File.separator).getPath());
			String path=f.getAbsolutePath();
			// path=path.substring(0,path.indexOf("webapps")-1);
			 path= path.substring(0,path.indexOf("target")-1);
			path=path.substring(0,path.lastIndexOf(File.separator)+1);

			System.out.println("file:///"+path+"blogStatic"+File.separator);
			//重置保存地址
			BlogConstants .resetNewPath("file:///"+path+BlogConstants.IOCAl_PATH+File.separator, BlogConstants.IOCAl_MAPPING);
			File   file=new File(BlogConstants.SAVE_PATH.substring("file:///".length()));
			if(!file.exists()) { 
				file.mkdirs();
			}
		
			
		
		
			registry.addResourceHandler("/"+BlogConstants.MAPPING_PATH+"**").addResourceLocations(BlogConstants.SAVE_PATH);
	}
}
